//
//  Car_CarFromInfoTableViewCell.m
//  CarUser
//
//  Created by ayi on 2019/1/9.
//  Copyright © 2019 王森林. All rights reserved.
//

#import "Car_CarFromInfoTableViewCell.h"

@implementation Car_CarFromInfoTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}


+ (Car_CarFromInfoTableViewCell *)initCellWithReuseIdentifier:(NSString *)reuseIdentifier andTab:(UITableView *)tab{
    Car_CarFromInfoTableViewCell *cell = [tab dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[Car_CarFromInfoTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _leftLab = [UILabel customInitLabWithFont:14 andTextColor:RGB(110, 110, 110) andAlign:NSTextAlignmentLeft];
        _rightLab = [UILabel customInitLabWithFont:14 andTextColor:Common_TextColor andAlign:NSTextAlignmentLeft];
        _moreBtn = ({
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.titleLabel.font = [UIFont systemFontOfSize:12];
            [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
            btn.backgroundColor = Common_TextLowColor;
            btn.layer.masksToBounds = YES;
            btn.layer.cornerRadius = 8;
            btn;
        });
        _lineview = [[UIView alloc]init];_lineview.backgroundColor = Common_SepeColor;
        
        [self.contentView addSubview:_leftLab];
        [self.contentView addSubview:_rightLab];
        [self.contentView addSubview:_moreBtn];
        [self.contentView addSubview:_lineview];
        
        [_leftLab mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.centerY;
            make.left.mas_equalTo(15);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(ceilf(self.leftLab.font.lineHeight));
        }];
        
        [_rightLab mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.centerY;
            make.left.equalTo(self.leftLab.mas_right).offset(10);
            make.width.mas_lessThanOrEqualTo(BOUNDWIDTH - 30 - 100 - 10);
            make.height.mas_equalTo(ceilf(self.rightLab.font.lineHeight));
        }];
        [_rightLab setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
        
        [_moreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            (void)make.centerY;
            make.left.equalTo(self.rightLab.mas_right).offset(10);
            make.width.mas_equalTo(50);
            make.height.mas_equalTo(ceilf(self.rightLab.font.lineHeight));
        }];
        
        [_lineview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(15);
            make.right.mas_equalTo(-15);
            (void)make.bottom;
            make.height.mas_equalTo(.5f);
        }];
        
        _moreBtn.hidden = YES;
    }
    return self;
}

- (void)addRac{
    
    @weakify(self);
    [[RACObserve(self.moreBtn, hidden) takeUntil:self.rac_prepareForReuseSignal] subscribeNext:^(id  _Nullable x) {
        @strongify(self);
        if ([x boolValue]) {
            [self.rightLab mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.mas_lessThanOrEqualTo(BOUNDWIDTH - 30 - 100 - 10);
            }];
        }else{
            [self.rightLab mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.mas_lessThanOrEqualTo(BOUNDWIDTH - 30 - 100 - 10 - 60);
            }];
        }
    }];
    
}


@end
